package com.gitee.wsl.jvm.okhttp.base


/**
 * A *valid* (not "unsatisfied") value of a `Content-Range` header field.
 *
 * Specification: [RFC 9110, Section 14.4](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.4)
 *
 * @property start the offset of the first byte in the content range.
 * @property endInclusive the offset of the last byte in the content range.
 * @property totalLength the total length of the document, or `-1` if it is unknown ('*').
 * @see Response.saveToResourceWithSupportingResumption
 */
class ContentRange(val start: Long, val endInclusive: Long, val totalLength: Long) {
    /**
     * `true` if this content range is at the end of the document.
     *
     * If the total length of the document is unknown, this is `false`.
     */
    val isLastPart: Boolean
        get() = endInclusive + 1 == totalLength

    override fun toString(): String =
        "$start-$endInclusive/${if (totalLength < 0) "*" else totalLength.toString()}"

}